#ifndef SMTP_H
#define SMTP_H

class SMTPWorker;

/**
* A class to send e-mail
*/
class SMTP
{
	public:
		/**
		* E-Mail Header information
		*/
		class Header
		{
			public:
				Header();
				Header( const Header& hdr );
				~Header();

				String nameFrom;		/**< from name 				  */
				String emailFrom;		/**< from e-mail address 	  */ 
				String emailTo;			/**< to e-mail address 		  */
				String emailCC;			/**< cc  e-mail	address		  */
				String emailBCC;		/**< bcc e-mail	address		  */
				String subject;			/**< subject 				  */ 
				bool8 defaultCodepage;
				bool8 bEmailAsHtml;
		};

		private:
		/**
		* E-Mail Header information
		*/
		class ASCIIHeader
		{
			public:
				ASCIIHeader();
				ASCIIHeader( const Header& hdr );
				~ASCIIHeader();

				char nameFrom[256];			/**< from name 				  */
				char emailFrom[256];		/**< from e-mail address 	  */ 
				char emailTo[256];			/**< to e-mail address 		  */
				char emailCC[256];			/**< cc  e-mail	address		  */
				char emailBCC[256];			/**< bcc e-mail	address		  */
				char subject[256];			/**< subject 				  */
				bool8 defaultCodepage;
				bool8 bEmailAsHtml;
			private:
				ASCIIHeader( const ASCIIHeader& hdr );
		};

		public:
		/**
		* sends an e-mail
		*
		* @param mailhost	hostname of the mail server
		* @param header		e-mail header information
		* @param message 	e-mail message
		*
		* @return true if e-mail is sent
		*/
		static bool8 send(const String& mailhost, const Header& header, const String& message);
		static bool8 sendDefault(const String& mailhost, const Header& header, const String& message);
		static bool8 blockingSend(const String& mailhost, const Header& header, const String& message);
		static bool8 blockingSendDefault(const String& mailhost, const Header& header, const String& message);

		friend class SMTPWorker;
};

inline
SMTP::Header::Header()
{
	bEmailAsHtml = false;
	defaultCodepage = false;
}

inline
SMTP::Header::Header(const SMTP::Header& hdr)
{
	nameFrom		= hdr.nameFrom;
	emailFrom		= hdr.emailFrom;
	emailTo			= hdr.emailTo;
	emailCC			= hdr.emailCC;
	emailBCC		= hdr.emailBCC;
	subject			= hdr.subject;
	defaultCodepage = hdr.defaultCodepage;
	bEmailAsHtml	= hdr.bEmailAsHtml;
}

inline
SMTP::Header::~Header()
{
}

inline
SMTP::ASCIIHeader::ASCIIHeader()
{
	nameFrom[0] = emailFrom[0] = emailTo[0] = emailCC[0] = emailBCC[0] = subject[0] = '\0';
	defaultCodepage = false;
	bEmailAsHtml = false;
}

inline
SMTP::ASCIIHeader::ASCIIHeader(const SMTP::Header& hdr)
{
	StringConversions::convert(nameFrom, hdr.nameFrom, 255);
	StringConversions::convert(emailFrom, hdr.emailFrom, 255);
	StringConversions::convert(emailTo, hdr.emailTo, 255);
	StringConversions::convert(emailCC, hdr.emailCC, 255);
	StringConversions::convert(emailBCC, hdr.emailBCC, 255);
	StringConversions::convert(subject, hdr.subject, 255);
	defaultCodepage = hdr.defaultCodepage;
	bEmailAsHtml = hdr.bEmailAsHtml;
}

inline
SMTP::ASCIIHeader::~ASCIIHeader()
{
}

#endif
